<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="javascript:;">所有作品</a></li>
        <li><a href="{:url('AdminWorks/add')}">添加作品</a></li>
    </ul>
    <form class="well form-inline margin-top-20" method="post" action="{:url('AdminWorks/index')}">
        赛事:
        <select class="form-control" name="category" style="width: 140px;">
            <option value='0'>全部</option>
            <foreach name="contest" item="con">
                <if condition="$category eq ''">
                    <if condition="$con.status eq 1">
                        <option value="{$con.id}" selected>{$con.title}</option>
                    <else/>
                        <option value="{$con.id}">{$con.title}</option>
                    </if>
                <else/>
                    <if condition="$con.id eq $category">
                        <option value="{$con.id}" selected>{$con.title}</option>
                    <else/>
                        <option value="{$con.id}">{$con.title}</option>
                    </if>
                </if>
            </foreach>
        </select>
        作者:
        <input type="text" class="form-control" name="author"
               value="{$author|default=''}"
               style="width: 200px;margin-left: 20px;">
        来源:
        <input type="text" class="form-control" name="source"
               value="{$source|default=''}"
               style="width: 200px;margin-left: 20px;">
        <input type="submit" class="btn btn-primary" value="搜索"/>
        <a class="btn btn-danger" href="{:url('AdminWorks/index')}">清空</a>
        <a class="btn btn-default" href="{:url('AdminWorks/export')}">导出</a>
    </form>
    <form class="js-ajax-form" action="" method="post">
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th width="15">
                    <label>
                        <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                    </label>
                </th>
                <th width="50">ID</th>
                <th>标题</th>
                <th>赛事</th>
                <th width="50">作者</th>
                <th width="160">上传时间</th>
                <th width="100">评分</th>
                <th width="95">操作</th>
            </tr>
            </thead>
            <foreach name="works" item="vo">
                <tr>
                    <td>
                        <input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
                               value="{$vo.id}" title="ID:{$vo.id}">
                    </td>
                    <td><b>{$vo.id}</b></td>
                    <td>
<!--                        <a href="">{$vo.title}</a>-->
                        <a href="{:cmf_url('portal/works/index',array('id'=>$vo['id']))}"
                           target="_blank">{$vo.title}</a>
                    </td>
                    <td>{$vo.contest_title}</td>
                    <td>{$vo.user_nickname}</td>
                    <td>{$vo.create_time}</td>
                    <td>
                        <notempty name="$vo.scores">
                            <foreach name="vo.scores" item="voo">
                                <p><span>{$voo.review_name}:{$voo.score}分</span></p>
                            </foreach>
                        </notempty>
                    </td>
                    <td>
                        <if condition="$vo.score eq 0">
                            <a class="btn btn-xs btn-warning" id="score" onclick="reviewScore({$vo['id']});">打分</a>
                        <a class="btn btn-xs btn-primary" href="{:url('AdminWorks/edit',array('id'=>$vo['id']))}">{:lang('EDIT')}</a>
                        </if>
                    </td>
                </tr>
            </foreach>
            <tfoot>
            <tr>
                <th width="15">
                    <label>
                        <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                    </label>
                </th>
                <th width="50">ID</th>
                <th>标题</th>
                <th>赛事</th>
                <th width="50">作者</th>
                <th width="160">上传时间</th>
                <th width="100">得分</th>
                <th width="95">操作</th>
            </tr>
            </tfoot>
        </table>
        <ul class="pagination">{$page|default=''}</ul>
    </form>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script src="__STATIC__/js/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
<!--<script src="__STATIC__/js/layer/layer.js"></script>-->
<script>
    $('.js-bootstrap-datetime').datetimepicker({
        minView: "month", //选择日期后，不会再跳转去选择时分秒
        language:  'zh-CN',
        format: 'yyyy-mm-dd',
        todayBtn:  1,
        autoclose: 1,
    });
    function reloadPage(win) {
        win.location.reload();
    }

    function reviewScore11($id) {
        alert($id)
        layer.open({
            type:2,
            title:false,
            closeBtn:1,
            shade:[0],
            area:['340px','300px'],
            shift:2,
            content:['review.html', 'no'],
        });
    }

    function reviewScore($id) {
        openIframeLayer("{:url('AdminWorks/review')}?id=" + $id, '请输入分数', {
            area: ['600px', '300px'],
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //do something

                var iframeWin          = window[layero.find('iframe')[0]['name']];
                var works = iframeWin.confirm();
                console.log(works);
                if (works.score.length == 0) {
                    layer.msg('请输入分数');
                    return;
                }
                $.ajax({
                    url: 'reviewPost',
                    type: 'post',
                    data: works,
                    dataType: 'JSON',
                    success: function (data) {
                        if (data.code == '1') {
                            noty({
                                text: data.msg,
                                type: 'success',
                                layout: 'topCenter',
                                modal: true,
                                timeout: 800,
                                callback: {
                                    afterClose: function () {
                                        if (data.url) {
                                            //返回带跳转地址
                                            window.location.href = data.url;
                                        } else {
                                            //刷新当前页
                                            reloadPage(window);
                                        }
                                    }
                                }
                            }).show();

                        } else if (data.code == '0') {
                            //art.dialog.alert(data.info);
                            //alert(data.info);//暂时处理方案
                            art.dialog({
                                content: data.msg,
                                icon: 'warning',
                                ok: function () {
                                    this.title(data.msg);
                                    return true;
                                }
                            });
                        }
                    }
                });
                layer.close(index); //如果设定了yes回调，需进行手工关闭
            }
        });
    }

    $(function () {
        setCookie("refersh_time", 0);
        Wind.use('ajaxForm', 'artDialog', 'iframeTools', function () {
            //批量复制
            $('.js-articles-copy').click(function (e) {
                var ids = [];
                $("input[name='ids[]']").each(function () {
                    if ($(this).is(':checked')) {
                        ids.push($(this).val());
                    }
                });

                if (ids.length == 0) {
                    art.dialog.through({
                        id: 'error',
                        icon: 'error',
                        content: '您没有勾选信息，无法进行操作！',
                        cancelVal: '关闭',
                        cancel: true
                    });
                    return false;
                }

                ids = ids.join(',');
                art.dialog.open("__ROOT__/index.php?g=portal&m=AdminWorks&a=copy&ids=" + ids, {
                    title: "批量复制",
                    width: "300px"
                });
            });
            //批量移动
            $('.js-articles-move').click(function (e) {
                var ids = [];
                $("input[name='ids[]']").each(function () {
                    if ($(this).is(':checked')) {
                        ids.push($(this).val());
                    }
                });

                if (ids.length == 0) {
                    art.dialog.through({
                        id: 'error',
                        icon: 'error',
                        content: '您没有勾选信息，无法进行操作！',
                        cancelVal: '关闭',
                        cancel: true
                    });
                    return false;
                }

                ids = ids.join(',');
                art.dialog.open("__ROOT__/index.php?g=portal&m=AdminWorks&a=move&old_term_id={$term.term_id|default=0}&ids=" + ids, {
                    title: "批量移动",
                    width: "300px"
                });
            });
        });
    });
</script>
</body>
</html>